<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getBannerListApi } from '@/apis/home'
import type { BannerType } from '@/apis/components/homeType'

// 轮播图列表
const bannerList = ref<[BannerType]>()

const prop = defineProps({
  id: {
    type: String,
    default: '',
  },
})

const ids = ref<string>('')

const getBannerList = async () => {
  if (prop.id === '') {
    ids.value = '1'
  } else {
    ids.value = prop.id
  }

  const res = await getBannerListApi(ids.value)
  bannerList.value = res.data.result
}
onMounted(() => getBannerList())
</script>

<template>
  <div>
    <el-carousel height="500px">
      <el-carousel-item v-for="item in bannerList" :key="item.id">
        <img :src="item.imgUrl" alt="" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<style lang="scss" scoped>
div {
  width: 100%;
  height: 550px;
  img {
    width: 100%;
    height: 500px;
  }
}
</style>
